﻿using System;
using System.Reflection;
using System.Xml.Serialization;
namespace Inaction.Util
{
    public static class AppHelper
    {
        static string executeDirectory = string.Empty;
        [XmlIgnore]
        public static string ExecuteDirectory
        {
            get
            {
                if (executeDirectory == string.Empty)
                {
                    executeDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
                    
                    if (System.Environment.OSVersion.Platform != PlatformID.WinCE)
                    {
                        executeDirectory = executeDirectory.Replace(@"file:\", "");
                    }
                }
                return executeDirectory + @"\";
            }
        }

        public static string AssemblyName
        {
            get
            {
                var projectName = System.AppDomain.CurrentDomain.FriendlyName;
                return projectName.Substring(0, projectName.LastIndexOf('.'));
            }
        }

        private static string fileDirectory = string.Empty;
        [XmlIgnore]
        public static string FileDirectory
        {
            get
            {
                if (fileDirectory == string.Empty)
                {
                    fileDirectory = ExecuteDirectory + @"Files\";
                }
                if (!System.IO.Directory.Exists(fileDirectory))
                {
                    System.IO.Directory.CreateDirectory(fileDirectory);
                }
                return fileDirectory;
            }
        }
        [XmlIgnore]
        public static string ConfigDirectory
        {
            get
            {
                var filePath = ExecuteDirectory + @"Config\";
                if (!System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.CreateDirectory(filePath);
                }
                return filePath;
            }
        }

        [XmlIgnore]
        public static string LogDirectory
        {
            get
            {
                var filePath = ExecuteDirectory + @"Log\";
                if (!System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.CreateDirectory(filePath);
                }
                return filePath;
            }
        }

        public static string UpdateDirectory
        {
            get
            {
                var filePath = ExecuteDirectory + @"UpdateFiles\";
                if (!System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.CreateDirectory(filePath);
                }
                return filePath;
            }
        }
    }
}
